package com.gy.utils;

import org.slf4j.MDC;
import java.util.UUID;

public class TraceUtil {

    // 生成或获取 Trace ID
    public static String getTraceId() {
        String traceId = MDC.get("traceId");
        if (traceId == null) {
            traceId = UUID.randomUUID().toString().replace("-", "");
            MDC.put("traceId", traceId);
        }
        return traceId;
    }

    // 清理 Trace ID
    public static void clear() {
        MDC.remove("traceId");
    }
}
